
On 08.02.2017 03:21, Dom Masters wrote:
> Hello Frank and Kai,
> I am half way through the new Puzzle Mode :)

cool!

> Also working on other modes :)
> However, I am stuck. If I have the moves in a PGN file, how can I put those
> into the game so I have the game history in Mastersoft Chess? Could you
> quote me to write a routine that I send a PCN to and it fills in the
> database?

I don't have code ready now, but can give some hints:

Basically, you will use the class CDatabase (see database.h).
It is for example used in DoMainCommandLoadGame() (in
PocketDatabase.cpp) to open a .pgn-file and load all games
(or in PocketHelper.cpp in LoadFromAutosave()).

Without having tested the code here, it could look like this:

CPGNParser* poParser;
CDatabase*  poDatabase;

// init database
poParser   = new CPGNParser();
poDatabase = new CDatabase(poParser);

poDatabase->open(sFilename.c_str());
CDatabaseGame* poGame = poDatabase->getNthGame(iCurrentGame);

Now you can use poGame to get the moves. Moves of a game are organized
in a tree, so that games with variations (or puzzles with multiple
solutions) can be stored.

// visit all nodes of the principal variation of a game
CGameNode* poNode = poGame->getRootNode();
while (poNode)
{
// do something with the move, e.g.
cout << poNode->getSAN() << endl;

poNode = poNode->getChild(0);
}







Let me know if we can help/explain stuff!

> Here's a list of more ideas. Hopefully we can do one or more of them:
>
> 1. Play via FICS?

I wouldn't do it. If FICS isn't already dead, Lichess (and probably
commercial sites like chess24) will kill it soon.
Also, the protocol is and old-fashioned nightmare. It took me really
long to write the Lichess-Support for PGM and it didn't pay off.

>
> 2. Need to be able to extract a commentary string for training mode that is
> built up from what the player is trying to do eg if they try to castle but
> cant then
>
> "You cannot castle because squares between your King and Rook are under
> attack".

Ok, this could be based on simpleboard.
In the case of a castle, the checks are similar to the checks in the
castle-generation code in simpleboard:


if (WK==sqPiece)
{   // white castles
if (cfCastles&CGBoard::CASTLE_W_OO)
{   // only generate castles if no square is attacked
if (EMPTY==sqBoard[bi+MR] && EMPTY==sqBoard[bi+MR+MR] &&
!(BAttacks(bi+MR) || BAttacks(bi+MR+MR) ||
BAttacks(bi)))
{
poMoves[miNumber++] = oOOWhite;
}
}


1. did the user enter a kingmove (e.g. e1-g1)
2. (not in the code above, implicitely checked by 3.) check if the king
is on e1 and a rook on h1.
3. is the castling-flag still set? if not, the king or the rook have
already moved and can't castle
4. check if the squares between the king and the rook are empty
5. check if the squares crossed by the king are not attacked


Another frequent beginners mistake is trying to move with pinned pieces.
This can be checked using getMoves() and getLegalMoves().
If the user entered a move which is in getMoves but not in
getLegalMoves, the move is infeasible, because it would leave the
own king in chess (--> moving piece is pinned).


// fill poMoves with all pseudolegal moves of the piece on bi
void getMoves(GBoardindex bi,
CGMove* poMoves,              // out: pseudolegal moves
Moveindex& miNumber) const;   // out: number of moves

// fill poMoves with all legal moves of the piece on bi
void getLegalMoves(GBoardindex bi,
CGMove* poMoves,         // out: legal(!) moves
Moveindex& miNumber);    // out: number of legal
moves


>
> 3. Commentary on current position? A simple form of computer gerated
> annotation?

A simple annotation like "white is slightly better" could be generated
using an engine-evaluation of the position.

>
> 4. Grinkgo option but would need to have Level and ELO ratings. Paid IAP at
> 50/50? Or else Rewarded Video at 50/50 (bightnmare to bookkeep LOL).

I'm currently still working on the engine strength but will take a break
soon - which would be a good time to port it to iOS.




> LIchess introduced a clever feature a few weeks ago: they extract
> puzzles from the games of a (logged in) user, so one can practice
> with positions from games he played - e.g. find a better move in
> the puzzle than the one he found in the actual game. But that only
> works when someone plays hundreds of games (and many users do that on
> LIchess).
>
> Regarding a puzzle-generator, there could be chess-specific options like
> the kind of tactical shot (sacrifices, fork, discovered check, etc)
> or the goal (mate-in-n, exchange into a won endgame, ...).
> One basic option is "difficulty". It can roughly be measured
> automatically (e.g. "how many nodes/what depth does the engine need to
> find the solution"), but a more precise difficulty measure should be
> based on solving times and percentage of correct solutions of
> customers trying to solve that puzzle.
> In the LIchess training mode, training positions have Elo-ratings.
> When a user successfully solves a puzzle, his tactics-rating increases
> and the puzzle's rating decreases (and vice versa if the user doesn't
> find the best moves).
>
>


